package com.wx.controller;


import com.wx.entity.SmbmsUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class RedisTestController {


    @Autowired
    RedisTemplate redisTemplate;
    HashMap<String,String> map = new HashMap<>();
    HashMap<String, SmbmsUser> map1 = new HashMap<>();
    @RequestMapping("/setStr")
    public String setStr(String value){
        //HashMap                  .put(key,value)
        map.put("strKey",value);
        redisTemplate.opsForValue().set("strKey",value);
        return "ok";
    }

    @RequestMapping("/getStr")
    public String getStr(String key){
        //HashMap                  .put(key,value)
        map.get(key);
        return  redisTemplate.opsForValue().get(key).toString();
    }


    @RequestMapping("/setUser")
    public String setUser( ){
        //HashMap                  .put(key,value)
        SmbmsUser smbmsUser = new SmbmsUser();
        smbmsUser.setUserName("张三");
        smbmsUser.setUserCode("zhangsan");
        smbmsUser.setUserPassword("123");
        redisTemplate.opsForValue().set("user",smbmsUser);
        return "ok";
    }

    @RequestMapping("/delUser")
    public String delUser(){
        redisTemplate.delete("user");
        return "ok";
    }

    @RequestMapping("/getUser")
    public SmbmsUser getUser(String key){
        //HashMap                  .put(key,value)
        //HashMap<String,Object>
        return  (SmbmsUser)redisTemplate.opsForValue().get(key);
    }

}
